package org.mydzms.com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.dzms.services.groupService;
import org.dzms.services.sljImgService;
import org.dzms.services.slxImgService;

import com.mysql.jdbc.interceptors.SessionAssociationInterceptor;

/**
 * Servlet implementation class GroupServlet
 */
public class GroupServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String gpid = request.getParameter("gpid");
		groupService gs = new groupService();
		request.setAttribute("gp", gs.findByGpId(Integer.parseInt(gpid)));
		String cp = request.getParameter("cp")==null?"1":request.getParameter("cp");
		String cond = request.getParameter("cond")==null?" ":request.getParameter("cond");
		request.setAttribute("gd", gs.findByGdId(Integer.parseInt(gpid)));
		String num = request.getParameter("num");
		request.getSession().setAttribute("num", num);
		
		sljImgService slj = new sljImgService();
		slxImgService slx = new slxImgService();
		if (Integer.parseInt(gpid) ==7) {
			request.setAttribute("gg", Integer.parseInt(gpid));
			request.setAttribute("slx", slx.findImgById(Integer.parseInt(gpid)));
		}else if(Integer.parseInt(gpid) == 8) {
			request.setAttribute("gg", Integer.parseInt(gpid));
			request.setAttribute("slj", slj.findImgById(Integer.parseInt(gpid)));
		}
		request.getRequestDispatcher("group.jsp").forward(request, response);
	}
}
